package com.gengzp.common.document.controller;

import com.gengzp.common.document.core.DocumentService;
import com.gengzp.common.document.model.resp.ControllerDocumentResp;
import com.gengzp.common.document.model.resp.MethodDocumentResp;
import com.gengzp.common.document.model.resp.ParamDocumentResp;
import com.gengzp.common.model.base.resp.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.repository.query.Param;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @ClassName DocumentController
 * @Description 接口文档相关接口
 * @Author gengzp
 * @Date 2025/5/21 0:35
 */
@RestController
@RequestMapping("/document")
public class DocumentController {

    @Autowired
    private DocumentService documentService;

    /**
     * 查询 controller控制器 层级的接口文档
     */
    @PostMapping("/search_controller")
    public Result<List<ControllerDocumentResp>> searchControllerDocument() {
        return Result.getSuccessResult(documentService.searchControllerDocument());
    }

    /**
     * 查询 method方法 层级的接口文档
     */
    @PostMapping("/search_method")
    public Result<MethodDocumentResp> searchMethodDocument(@Param("controllerUrl") String controllerUrl) {
        if (controllerUrl == null || controllerUrl.isBlank()) {
            return Result.getFailResult("controllerUrl不能为空");
        }
        return Result.getSuccessResult(documentService.searchMethodDocument(controllerUrl));
    }

    /**
     * 查询 参数 文档
     */
    @PostMapping("/search_param")
    public Result<List<ParamDocumentResp>> searchParamDocument(@Param("controllerUrl") String controllerUrl,
                                                               @Param("methodUrl") String methodUrl) {
        if (controllerUrl == null || controllerUrl.isBlank()) {
            return Result.getFailResult("controllerUrl不能为空");
        }
        if (methodUrl == null || methodUrl.isBlank()) {
            return Result.getFailResult("methodUrl不能为空");
        }
        return Result.getSuccessResult(documentService.searchParamDocument(controllerUrl, methodUrl));
    }

}
